package org.hlopik.riverGuide.services;

import java.util.ArrayList;
import java.util.List;
import org.hlopik.riverGuide.client.model.dto.RiverGuideDTO;
import org.hlopik.riverGuide.client.services.RiverGuideService;
import org.hlopik.riverGuide.dao.RiverGuideDao;
import org.hlopik.riverGuide.shared.RiverGuide;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author f
 */
@Service
public class RiverGuideServiceImpl implements RiverGuideService {

    @Autowired
    private RiverGuideDao riverGuideDao;

    public void setRiverGuideDao(RiverGuideDao riverGuideDao) {
        this.riverGuideDao = riverGuideDao;
    }

    public void addRiverGuide(RiverGuideDTO riverGuide) {
        RiverGuide result = new RiverGuide();
        if (riverGuide.getId() != null && ! "".equals(riverGuide.getId())) {
            result.setId(riverGuide.getId());
        }        
        result.setName(riverGuide.getName());
        result.setDescription(riverGuide.getDescription());
        riverGuideDao.addRiverGuide(result);
    }

    public List<RiverGuideDTO> getAllRiverGuides() {
        List<RiverGuide> data = riverGuideDao.getAllRiverGuides();
        List<RiverGuideDTO> result = new ArrayList<RiverGuideDTO>();
        for (RiverGuide riverGuide : data) {
            RiverGuideDTO riverGuideDTO = new RiverGuideDTO();
            riverGuideDTO.setId(riverGuide.getId());
            riverGuideDTO.setName(riverGuide.getName());
            riverGuideDTO.setDescription(riverGuide.getDescription());
            result.add(riverGuideDTO);
        }
        return result;
    }

}
